package main

import "fmt"

func main() {
	var n, m, x int
	_, _ = fmt.Scan(&n, &m)

	var start []int
	data := make([][]int, m)
	for i := 0; i < m; i++ {
		_, _ = fmt.Scan(&x)
		data[i] = make([]int, x)
		flag := false
		for j := 0; j < x; j++ {
			_, _ = fmt.Scan(&data[i][j])
			if data[i][j] == 0 {
				flag = true
			}
		}
		if flag {
			start = data[i]
		}
	}

	fm := make(map[int]struct{})
	for _, v := range start {
		fm[v] = struct{}{}
	}

	for {
		flag := true

		for j := len(data) - 1; j >= 0; j-- {
			fmt.Println(fm)
			fmt.Println(data[j])
			for _, v := range data[j] {
				if _, ok := fm[v]; ok {
					start = append(start, data[j]...)
					flag = false
					data = append(data[:j], data[j+1:]...)
					break
				}
			}

			if !flag {
				for _, v := range start {
					fm[v] = struct{}{}
				}
			}
		}

		if flag {
			break
		}
	}

	fmt.Println(start)
	for _, v := range start {
		fm[v] = struct{}{}
	}
	fmt.Println(len(fm))
}
